package com.homepage.domain;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.io.Serializable;
import java.time.ZonedDateTime;

/**
 * A Employee.
 */
@Entity
@Table(name = "employee")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Getter
@Setter
@ToString
public class Employee implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    @NotNull
    @Size(max = 30)
    @Column(name = "name", length = 30, nullable = false)
    private String name;

    @NotNull
    @Size(max = 30)
    @Column(name = "position", length = 30, nullable = false)
    private String position;

    @NotNull
    @Size(max = 150)
    @Column(name = "description", length = 150, nullable = false)
    private String description;

    @NotNull
    @Size(max = 40)
    @Column(name = "email", length = 40, nullable = false)
    private String email;

    @NotNull
    @Size(max = 20)
    @Column(name = "phone_number", length = 20, nullable = false)
    private String phoneNumber;

    @NotNull
    @Column(name = "hire_date", nullable = false)
    private ZonedDateTime hireDate;

    @ManyToOne
    @JsonIgnoreProperties(value = { "employees", "featurettes", "headlines", "partners", "companyLogo" }, allowSetters = true)
    private Company company;



    public Employee id(Long id) {
        this.setId(id);
        return this;
    }

    public Employee name(String name) {
        this.setName(name);
        return this;
    }


    public Employee position(String position) {
        this.setPosition(position);
        return this;
    }


    public Employee description(String description) {
        this.setDescription(description);
        return this;
    }

    public Employee email(String email) {
        this.setEmail(email);
        return this;
    }

    public Employee phoneNumber(String phoneNumber) {
        this.setPhoneNumber(phoneNumber);
        return this;
    }


    public Employee hireDate(ZonedDateTime hireDate) {
        this.setHireDate(hireDate);
        return this;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof Employee)) {
            return false;
        }
        return id != null && id.equals(((Employee) o).id);
    }

    @Override
    public int hashCode() {
        return getClass().hashCode();
    }
}
